package com.ccb.sc.common.rule.medal.rules;

import com.ccb.sc.common.modules.member.enums.MedalType;
import com.ccb.sc.common.rule.medal.fact.MedalFact;
import lombok.extern.slf4j.Slf4j;
import org.jeasy.rules.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author ken
 * @version 1.0
 * @date 2022/8/26 0:36
 */
@Slf4j
@Component
@Rule(name = "优你同行", description="订单转换次数达到1次 或 预约直播次数达到1次")
public class Medal1Rule extends AbstractMedalRule {

    private static final MedalType MEDAL_TYPE = MedalType.YOU_NI_TONG_XING;

    @Condition
    public boolean condition(@Fact("fact") MedalFact fact) {
        return getCondition(fact, MEDAL_TYPE);
    }

    @Action
    public void action(@Fact("fact") MedalFact fact) {
        log.info("用户[{}]活动勋章[{}]", fact.getMemberId(), MEDAL_TYPE.getName());
        saveMedal(fact.getMemberId(), MEDAL_TYPE, fact.getLightUpReason());
    }

    @Priority
    public int getPriority() {
        return MEDAL_TYPE.getValue();
    }
}
